package ru.ifmo.croak.api;

import java.util.List;

/**
 * {@code MessageQuery} represents an active message query.
 * All implementations of this interface must be tread-safe.
 *
 * @author Roman Elizarov
 */
public interface MessageQuery {
    /**
     * Returns requests that corresponds to this query.
     */
    public QueryRequest getRequest();

    /**
     * Returns a list of messages that are known to currently match the query.
     * Messages are sorted by time in ascending order.
     */
    public List<Message> getMessages();

    /**
     * Closes this query. Further query updates stop.
     */
    public void close();

    /**
     * Assigns listener to get notified on new messages matching query.
     * On invocation of this method, the current list of messages will be passed to the listener
     * via repeated invocation of its {@link MessageListener#messageAvailable(Message)} method.
     */
    public void setMessageListener(MessageListener listener);
}
